package cn.chenxiejia;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/***
 * @program: maven
 * @ClassName: Imges2
 * @Description: 画一个太极图
 * @Author: chenxiejia
 * @Date: 2022/1/21 10:37
 * @version : V1.0
 */
public class Imges2 {
    public static void main(String[] args) throws IOException {
        //创建画板，1为jpg格式，2为png格式在后面再增加一个参数为透明度
        BufferedImage i = new BufferedImage(800, 800, 1);
        //创建画笔
        var m = i.createGraphics();
        //设置平滑度
        m.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        m.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        m.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        //设置画笔颜色
        m.setColor(Color.ORANGE);
        //fill为填充，fillRect填充矩形
        m.fillRect(0, 0, 800, 800);
        m.setColor(Color.WHITE);
        //m.drawArc(200, 200, 200, 200, 0, 90);
        //填充圆弧，画半圆
        m.fillArc(150, 150, 500, 500, 90, 180);

        m.setColor(Color.BLACK);
        m.fillArc(150, 150, 500, 500, -90, 180);

        m.setColor(Color.WHITE);
        m.fillArc(275, 150, 250, 250, -90, 180);

        m.setColor(Color.BLACK);
        m.fillArc(275, 400, 250, 250, 90, 180);

        m.setColor(Color.BLACK);
        m.fillOval(350, 225, 100, 100);

        m.setColor(Color.WHITE);
        //椭圆
        m.fillOval(350, 475, 100, 100);
        //关闭
        m.dispose();
        //画板写入文件
        ImageIO.write(i, "png", new File("taiji.png"));
        //系统运行打开图片
        Runtime.getRuntime().exec("cmd /k start taiji.png");

    }
}
